import httpRequest from '@/utils/hqqtRequest'

import type { UserResponseData, User, AllRolesListData, AssignUserRole } from './type'

enum API {
    // 获取用户数据
    USER_INFO = '/admin/acl/user/',
    // 新增管理用户
    ADD_USER = '/admin/acl/user/save',
    // 修改管理用户
    PUT_USER = '/admin/acl/user/update',
    // 根据用户获取角色数据
    USER_ROLE = '/admin/acl/user/toAssign/',
    // 根据用户分配角色
    USER_ASSIGN_ROLE = '/admin/acl/user/doAssignRole',
    // 单个删除用户数据
    DELETE_USER = '/admin/acl/user/remove/',
    // 批量删除数据
    DELETE_BATCH_USER = '/admin/acl/user/batchRemove'
}

export const getUserInfoAPI = (page: number, limit: number,username: string) => httpRequest<any, UserResponseData>({ url: API.USER_INFO + `${page}/${limit}?username=${username}` })

export const updateUserAPI = (data: User) => {
    if (!data.id) {
        return httpRequest<any, any>({ url: API.ADD_USER, method: 'POST', data })
    } else {
        return httpRequest<any, any>({ url: API.PUT_USER, method: 'PUT', data })
    }
}

export const getUserRoleAPI = (adminId: number | string) => httpRequest<any, AllRolesListData>({ url: API.USER_ROLE + adminId })

export const assignUserRoleAPI = (data: AssignUserRole) => httpRequest<any, any>({ url: API.USER_ASSIGN_ROLE, method: 'POST', data })

export const deleteUserRoleAPI = (id: number | string) => httpRequest<any, any>({ url: API.DELETE_USER + id, method: 'DELETE' })

export const deleteUserRoleBatchAPI = (idLIst: number[] | string[]) => httpRequest<any, any>({ url: API.DELETE_BATCH_USER, method: 'DELETE', data: idLIst })
